package com.example.checkctf.NetworkRequest;

import com.example.baselibrary.Bean.CheckResultBean;
import com.example.baselibrary.Bean.CheckTicketBean;
import com.example.baselibrary.Bean.Movie;
import com.example.baselibrary.Bean.PickFaceBean;
import com.example.baselibrary.Bean.PickResultBean;

import org.json.JSONObject;

import io.reactivex.Observable;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import retrofit2.http.Body;

public class ApiMethods {

    /**
     * 封装线程管理和订阅的过程
     */
    public static void ApiSubscribe(Observable observable, Observer observer) {
        observable.subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    /**
     * 用于获取豆瓣电影Top250的数据
     *
     * @param observer 由调用者传过来的观察者对象
     * @param start    起始位置
     * @param count    获取长度
     */
    public static void getTopMovie(Observer<Movie> observer, int start, int count) {
        ApiSubscribe(ApiStrategy.getApiService().getTopMovie(start, count), observer);
    }

    //用于检查介质的可行性
    public static void checkTicketJson(Observer<CheckResultBean> observer, CheckTicketBean checkTicketBean) {
        ApiSubscribe(ApiStrategy.getApiService().checkTicketJson(checkTicketBean), observer);
    }

    public static void pickFaceJson(Observer<PickResultBean> observer, PickFaceBean pickFaceBean) {
        ApiSubscribe(ApiStrategy.getApiService().pickFaceJson(pickFaceBean),observer);
    }





}
